class Solution {
public:
    double maxAverageRatio(vector<vector<int>>& classes, int extraStudents) {
        priority_queue<pair<double, int>> pq;
        for (int i = 0; i < classes.size(); i++) {
            double a = (classes[i][0] * 1.0) / classes[i][1];
            double b = ((classes[i][0] + 1) * 1.0) / (classes[i][1] + 1);
            pq.push({ b - a, i });
        }

        while (extraStudents--) {
            auto cla = pq.top();
            pq.pop();

            classes[cla.second][0]++, classes[cla.second][1]++;
            double a = (classes[cla.second][0] * 1.0) / classes[cla.second][1];
            double b = ((classes[cla.second][0] + 1) * 1.0) / (classes[cla.second][1] + 1);
            pq.push({ b - a, cla.second });
        }

        double ret = 0;
        for (auto& cla : classes) {
            ret += (cla[0] * 1.0) / cla[1];
        }
        return ret / classes.size();
    }
};